package client;

import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.DatagramPacket;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.util.CharsetUtil;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;

public class MyClient {

    public static void main(String[] args) throws InterruptedException {


        EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap b = new Bootstrap();
            b.group(group).channel(NioDatagramChannel.class)
                    .option(ChannelOption.SO_BROADCAST,true)
                    .handler(new UdpClientHandler());
              b.bind(0).sync().channel().closeFuture().await();
            // 向网段类所有机器广播发UDP
//            ch.writeAndFlush(
//                    new DatagramPacket(
//                            Unpooled.copiedBuffer("啪啪啪来拉！！！", CharsetUtil.UTF_8),
//                            new InetSocketAddress(
//                                    "127.0.0.1",9999
//                            ))).sync();
//            if(!ch.closeFuture().await(15000)){
//                System.out.println("查询超时！！！");
//            }
        }
        finally {
            group.shutdownGracefully();
        }
    }

}
